package com.hmis.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hmis.domain.CheckItem;
import com.hmis.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@Controller
public class CheckItemDAO implements InitializingBean {

    public static CheckItemService checkItemService;
    public static CheckItemDAO checkItemDAO;
    @Autowired
    private CheckItemService checkItem;

    public boolean isValidCheckItem(long patientId, long itemId, int status) {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("patient_id", patientId);
        queryWrapper.eq("item_id", itemId);
        queryWrapper.eq("status", status);
        List<CheckItem> list = checkItemService.list(queryWrapper);

        return list != null && list.size() != 0;

    }

    public boolean addCheckItem(CheckItem checkItem) {
        return checkItemService.save(checkItem);
    }

    public List<CheckItem> findCheckItemByPatientId(long patientId) {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("patient_id", patientId);
        List<CheckItem> list = checkItemService.list(queryWrapper);
        return list;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        checkItemService = checkItem;
        checkItemDAO = this;
    }
}
